package logic

import (
	"context"
	"shenzhou/B/srv/models/mysql"

	"shenzhou/B/srv/car"
	"shenzhou/B/srv/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UsersListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUsersListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UsersListLogic {
	return &UsersListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UsersListLogic) UsersList(in *car.UsersListRequest) (*car.UsersListResponse, error) {
	// todo: add your logic here and delete this line

	u := mysql.User{}
	list, err := u.List(in.Status)
	if err != nil {
		return nil, err
	}
	var usersList []*car.UsersList
	for _, user := range list {
		c := car.UsersList{
			Tel:    user.Tel,
			Status: user.Status,
		}
		usersList = append(usersList, &c)
	}
	return &car.UsersListResponse{List: usersList}, nil
}
